package me.spring.cloud.components.starter.oss.configuration;

import me.spring.cloud.common.components.oss.cloud.CloudStorageService;
import me.spring.cloud.common.components.oss.cloud.aliyun.AliyunCloudStorageServiceImpl;
import me.spring.cloud.common.components.oss.cloud.qcloud.QcloudCloudStorageServiceImpl;
import me.spring.cloud.common.components.oss.cloud.qiniucloud.QiniuCloudStorageServiceImpl;
import me.spring.cloud.components.starter.oss.properties.OssProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

/**
 * @description: 文件存储配置
 * @author: luffy
 * @create: 2018-09-20 12:01
 **/
@Configuration
public class CloudStorageConfiguration {

  @Autowired
  private OssProperties ossProperties;

  @Bean
  protected CloudStorageService getCloudStorageService() {
    Assert.notNull(ossProperties, "ossProperties must be set");
    if (null != ossProperties.getAliyun()) {
      return new AliyunCloudStorageServiceImpl(ossProperties.getAliyun());
    } else if (null != ossProperties.getQcloud()) {
      return new QcloudCloudStorageServiceImpl(ossProperties.getQcloud());
    } else if (null != ossProperties.getQiniucloud()) {
      return new QiniuCloudStorageServiceImpl(ossProperties.getQiniucloud());
    }
    throw new IllegalArgumentException("oss configuration must be set");
  }
}
